# 3）不同价格的房源数量（散点图）【横坐标为价格，纵坐标为数量】

import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.commons.utils import JsCode
df = pd.read_excel('data_clean.xlsx')

from pyecharts.faker import Faker
price_bins = [0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000]

df["price_range"] = pd.cut(x=df["price"],bins=price_bins)
locations = [location for location in df['price_range'].value_counts().items()]

x_data =['1000','2000','3000','4000','5000','6000','7000,''8000','9000','10000']
y_data = []
for i in range(len(locations)):
    y_data.append(locations[i][1])
c = (
    Scatter()
    .add_xaxis(x_data)
    .add_yaxis("数量", y_data)
    .set_global_opts(
        title_opts=opts.TitleOpts(title="房源散点图"),
        visualmap_opts=opts.VisualMapOpts(max_=600),
    )
    .render("房屋分布图散点图.html")
)
